package com.abner.springcloudprovideruser.entity;

import com.netflix.discovery.provider.Serializer;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @Author: Abner.Jiang
 * @Description:
 * @Date: Created on 2019/12/20 10:17
 * @ProjectName: springcloud-provider-user
 */
@Data
public class SecurityUser implements UserDetails {
    private static final long serialVersionUID = 2321896886353190733L;
    private long id;
    private String username;
    private String password;
    private String role;

    public SecurityUser(String username, String password, String role) {
        this.username = username;
        this.password = password;
        this.role = role;
    }

    public SecurityUser() {
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        SimpleGrantedAuthority authority = new SimpleGrantedAuthority(this.role);
        authorities.add(authority);
        return authorities;
    }

    /**
     * 判断账户是否过期： true：未过期，false ： 已过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 判断账户是否已被锁定： true：未锁定，false ： 已锁定
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 凭证是否未过期：  true：未过期，false：已过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 是否启用用户  true ： 启用，false：禁用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
